@extends('Admin.layout.layout')
@section('title','门户管理')
@section('home','新闻管理')
@section('weizhi','查看')
@section('con')
 	
 	<header class="panel-heading" style="display:block;position:relative;height:40px">
       <font style="display:block;position:absolute;float:left"><font>门户信息列表</font></font>
        <div class="nav search-row" id="top_menu" style="position: absolute;float: left;margin-left: 100px;margin-top: 6px;">
            
            <ul class="nav top-menu">                    
                <li style="border:0px">
                    <form class="navbar-form" method="get" action="{{url('/admin/portalpost/index')}}">
                        <input class="form-control" placeholder="Search" name="keywords" value="{{$data['keywords'] or ''}}" type="text">
                        <button class="btn btn-default"><span class="icon_cloud-upload_alt"></span><font><font class=""> 搜索</font></font></button>                        
                    </form>
                </li>                    
            </ul>
                            
        </div>
    </header>
    
	<table class="table table-striped table-advance table-hover" style="margin-top: 5px;">

	<tbody>
	  <tr>
	     <th> 序号</th>
	     <th>id</th>
	     <th> 新闻标题</th>
	     <th>所属板块</th>
	     <th> 发稿时间</th>
	     <th>发稿人</th>
	     <th>状态</th>
	     <th> 操作</th>		
	  </tr>
	  <?php 
	  		$arr=array('普通','头版','首页推送');
	   ?>
	  @foreach($posts as $key=>$value)
	  <tr>
	     <td>{{$count++}}</td>
	     <td>{{$value->id}}</td>
	     <td>{{$value->title}}</td>
	     <td>{{$value->tname}}</td>
	     <td>{{date('Y-m-d',$value->ctime)}}</td>
	     <td>{{$value->uname}}</td>
         <td hid="{{$value->id}}" style="cursor:pointer;" onclick="func({{$value->id}})">{{$arr[$value->hot]}}</td>
         <!-- <td type="hidden">{{csrf_field()}}</td> -->
	     <td>
	      <div class="btn-group">
	          <a class="btn btn-primary" href="{{url('admin/portalpost/scan',['id'=>$value->id])}}">查看</a>
	          <a class="btn btn-success" href="{{url('admin/portalpost/edit',['id'=>$value->id])}}">修改</a>
	          <a class="btn btn-danger" href="{{url('admin/portalpost/delete',['id'=>$value->id])}}">删除</a>
	      </div>
	      </td>
	  </tr>
	  @endforeach
	</tbody>
</table>
</form>
<div style="text-align: center;">
	
<!-- {!! $posts->render() !!} -->
	{!! $posts -> appends($data) -> render() !!}
</div>
<span style="color:red;font-size: 12px;">{{session('success')}}</span>
<span style="color:red;font-size: 12px;">{{session('error')}}</span>


<script type="text/javascript" src="/bootcss/admin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
  $(".btn-danger").click(function(){
      res = confirm('确定要删除该条信息?');
      if(!res){
          return false;
      }
  });
</script>

@endsection
@section('myjs')
	<script>
		function func(id)
		{
			//alert(id+"--"+hot);
			var hid=id;
			// alert(hid);
			var v=$('td[hid="'+id+'"]').html();
			//alert(v);
			var arr=['普通','头版','首页推送'];
			var hot=arr.indexOf(v);
			//alert(hot);
			 $.ajaxSetup({
		        headers: {
		             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		         }
			 });


			 var arr=['普通','头版','首页推送'];
			 $.get('/admin/portalpost/hot',{pid:id,hot:hot},function(data){
			  		// $('#hot').html(data);
		  		$('td[hid="'+id+'"]').html(arr[data]);
		  		hot=data;

			});
			 
		}		
	</script>
@endsection